home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / flonum.h < prev    next >
C/C++ Source or Header  |  1990-04-03  |  5KB  |  179 lines

  1. #ifndef FLONUM_H
  2. #define FLONUM_H
  3.  
  4. /* Defs and macros for floating point code.  This stuff is heavily based
  5.    on Scott McCauley's code, except that this version works :-} */
  6.  
  7.  
  8. /* These definitions work for machines where an SF value is
  9.    returned in the same register as an int.  */
  10.  
  11. #ifndef SFVALUE  
  12. #define SFVALUE int
  13. #endif
  14.  
  15. #ifndef INTIFY
  16. #define INTIFY(FLOATVAL)  (intify.f = (FLOATVAL), intify.i)
  17. #endif
  18.  
  19. /* quasi-IEEE floating point number definitions */
  20.  
  21. struct bitfloat {
  22.     unsigned long sign : 1;
  23.     unsigned long exp  : 8;
  24.     unsigned long mant : 23;
  25. };
  26.  
  27. struct bitdouble {
  28.     unsigned long sign  : 1;
  29.     unsigned long exp   : 11;
  30.     unsigned long mant1 : 20;
  31.     unsigned long mant2;
  32. };
  33.  
  34. union double_di {
  35.         double d;
  36.     long   i[2];
  37. };
  38.  
  39. union flt_or_int {
  40.         long  i;
  41.         float f;
  42. };
  43.  
  44. #ifdef WORDS_BIG_ENDIAN
  45. #  define HIGH 0
  46. #  define LOW 1
  47. #else
  48. #  define HIGH 1
  49. #  define LOW 0
  50. #endif
  51.  
  52. /*
  53.  * all float/double/long now coded in assembler, dont define anything
  54.  * below this line
  55.  */
  56. #if 0
  57. /* start of symbolic asm definitions */
  58.  
  59. /* you may have to change the g's to d's if you start getting
  60.    illegal operands from as */
  61.  
  62. #define MUL(a, b) \
  63.     asm volatile ("mulu    %2,%0"     : "=d" (b)    : "0" (b) , "g" (a))
  64.  
  65. #define DIV(a, b) \
  66.     asm volatile ("divu %2,%0"     : "=d" (b)    : "0" (b) , "g" (a))
  67.  
  68. #define SWAP(a)      \
  69.     asm volatile ("swap    %0"     : "=r" (a)     : "0" (a))
  70.  
  71. #define ASL2(r1, r2) { \
  72.     asm volatile ("asll  #1,%0"    : "=d" (r2)     : "0" (r2));    \
  73.     asm volatile ("roxll #1,%0" : "=d" (r1)    : "0" (r1));    \
  74.     }
  75.  
  76. #define ASL3(r1, r2, r3) { \
  77.     asm volatile ("asll  #1,%0" : "=d" (r3)     : "0" (r3));    \
  78.     asm volatile ("roxll #1,%0" : "=d" (r2)     : "0" (r2));    \
  79.     asm volatile ("roxll #1,%0" : "=d" (r1)     : "0" (r1));     \
  80.     }
  81.  
  82. #define ASR2(r1, r2) {    \
  83.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  84.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  85.     }
  86.  
  87. #define ASR3(r1, r2, r3) { \
  88.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  89.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  90.     asm volatile ("roxrl #1,%0" : "=d" (r3)     : "0" (r3));    \
  91.     }
  92.  
  93. #define ASR4(r1, r2, r3, r4) { \
  94.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  95.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  96.     asm volatile ("roxrl #1,%0" : "=d" (r3)    : "0" (r3));    \
  97.     asm volatile ("roxrl #1,%0" : "=d" (r4)     : "0" (r4));    \
  98.     }
  99.  
  100. #define ADD2(r1, r2, r3, r4) { \
  101.     asm volatile ("addl  %2,%0"    : "=g" (r4)     : "0" (r4) , "g" (r2));    \
  102.     asm volatile ("addxl %2,%0"    : "=g" (r3)    : "0" (r3) , "g" (r1));    \
  103.     }
  104.  
  105. /* y <- y - x  */
  106. #define SUB3(x1, x2, x3, y1, y2, y3) { \
  107.     asm volatile ("subl  %2,%0"    : "=g" (y3)    : "0" (y3) , "d" (x3));    \
  108.     asm volatile ("subxl %2,%0"    : "=g" (y2)     : "0" (y2) , "d" (x2)); \
  109.     asm volatile ("subxl %2,%0"    : "=g" (y1)     : "0" (y1) , "d" (x1));    \
  110.     }
  111.  
  112. /* sub4 here is rather complex, as the compiler is overwhelmed by me wanting
  113.    to have 8 data registers allocated for mantissa accumulators.  Help it out
  114.    by declaring a temp that it can move stuff in and out of.  */
  115. #define SUB4(x1, x2, x3, x4, y1, y2, y3, y4) { \
  116.     register long temp = y4;                          \
  117.     asm volatile ("subl  %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x4)); \
  118.     y4 = temp; temp = y3;                           \
  119.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x3)); \
  120.     y3 = temp; temp = y2;                          \
  121.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x2)); \
  122.     y2 = temp; temp = y1;                          \
  123.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x1)); \
  124.     y1 = temp;                                  \
  125.     }
  126.  
  127. #define NEG(r1, r2) { \
  128.     asm volatile ("negl  %0"    : "=d" (r2)    : "0" (r2));    \
  129.     asm volatile ("negxl %0"     : "=d" (r1)     : "0" (r1));    \
  130.     } 
  131.  
  132. /* switches for which routines to compile.  All the single-float and
  133. long-int arithmetic routines are turned off here, as they were all
  134. done in assembly language last year.  */
  135.  
  136. /*
  137. #define L_umulsi3
  138. #define L_mulsi3
  139. #define L_udivsi3
  140. #define L_divsi3
  141. #define L_umodsi3
  142. #define L_modsi3
  143. #define L_lshrsi3
  144. #define L_lshlsi3
  145. #define L_ashrsi3
  146. #define L_ashlsi3
  147. */
  148. /*    These are now in kai-uwe .s files
  149.   #define L_divdf3
  150.   #define L_muldf3
  151.   #define L_negdf2
  152.   #define L_adddf3
  153.   #define L_subdf3
  154.   #define L_cmpdf2
  155.   #define L_fixunsdfsi
  156.   #define L_floatsidf
  157. */
  158. /*
  159.   these three are now in gnulib2 (were in dflonum.h pre gcc1.36)
  160. #define L_fixunsdfdi
  161. #define L_fixdfdi
  162. #define L_floatdidf
  163.  
  164. #define L_addsf3
  165. #define L_negsf2
  166. #define L_subsf3
  167. #define L_cmpsf2
  168. #define L_mulsf3
  169. #define L_divsf3
  170. */
  171.  
  172. /* These too are now in kai-uwe .s files
  173.    #define L_truncdfsf2
  174.    #define L_extendsfdf2
  175. */
  176. #endif /* #if 0 */
  177.  
  178. #endif /* FLONUM_H */
  179.